import 'package:black_movice/config/configs.dart';
import 'package:black_movice/utils/Utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';

class CuAppBar extends StatelessWidget implements PreferredSizeWidget {
  // 标题
  final String title;
  // 按钮描述
  final String actionText;
  // 点击按钮后得回调
  final VoidCallback onClick;
  static void defaultClick() {
    Utils.logDebug("被点击");
  }

  const CuAppBar(
      {super.key,
      this.title = '标题',
      this.actionText = "按钮",
      this.onClick = defaultClick});

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      bottom: false,
      child: AppBar(
        backgroundColor: Colors.transparent,
        shadowColor: Colors.transparent,
        surfaceTintColor: Colors.transparent,
        // foregroundColor: Colors.red,
        leading: IconButton(
          onPressed: () {
            Get.back();
          },
          icon: Icon(Icons.arrow_back),
        ),
        centerTitle: true,
        title: Text(
          title,
          style: TextStyle(fontSize: Configs.lgTitleSize_16),
        ),
        actions: [TextButton(onPressed: onClick, child: Text(actionText))],
      ),
    );
  }

  @override
//  首选大小为标准appBar高度
  Size get preferredSize => const Size.fromHeight(kToolbarHeight);
}
